<?php
/**
 *
 * Copyright  FaShop
 * License    http://www.fashop.cn
 * link       http://www.fashop.cn
 * Created by FaShop.
 * User: hanwenbo
 * Date: 2020/10/5
 * Time: 12:21 下午
 *
 */

namespace ezswoole\utils;


class ParamsSet
{
	function __construct( array $data, $allowFields = [] )
	{
		$this->data        = $data;
		$this->allowFields = $allowFields;
	}

	protected $data;
	// 默认允许所有字段
	protected $allowFields = [];

	// 把没有isset的过滤掉
	public function isset()
	{
		$data = [];

		if( $this->allowFields !== [] ){
			foreach( $this->allowFields as $field ){
				if( isset( $this->data[$field] ) ){
					$data[$field] = $this->data[$field];
				}
			}
		} else{
			$data = $this->data;
		}
		return $data;
	}
}